<?php

/**
 * contribuyente actions.
 *
 * @package    sf_sandbox
 * @subpackage contribuyente
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contribuyenteActions extends sfActions
{
   public function executeShow(sfWebRequest $request)
  {
    $this->contribuyente = Doctrine_Core::getTable('Contribuyente')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->contribuyente);
  }
    
    
    public function executeIndex(sfWebRequest $request)
  { 
    
      $this->contribuyentes = $this->getPager(ContribuyenteTable::getBuscarContribuyentes("", "",""), $request->getGetParameter('page'), "Contribuyente");
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new ContribuyenteForm();
  }
  
   
  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new ContribuyenteForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($contribuyente = Doctrine_Core::getTable('Contribuyente')->find(array($request->getParameter('id'))), sprintf('Object contribuyente does not exist (%s).', $request->getParameter('id')));
    $this->form = new ContribuyenteForm($contribuyente);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($contribuyente = Doctrine_Core::getTable('Contribuyente')->find(array($request->getParameter('id'))), sprintf('Object contribuyente does not exist (%s).', $request->getParameter('id')));
    $this->form = new ContribuyenteForm($contribuyente);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  { 
    
   $request->checkCSRFProtection();

    $this->forward404Unless($contribuyente = Doctrine_Core::getTable('Contribuyente')->find(array($request->getParameter('id'))), sprintf('Object contribuyente does not exist (%s).', $request->getParameter('id')));
    
 $contribuyente->delete();


 $this->redirect('contribuyente/index');
  }
public function executeEliminar(sfWebRequest $request) {
           $this->forward404Unless($this->contribuyente = Doctrine_Core::getTable('Contribuyente')->find(array($request->getParameter('id'))), sprintf('Object contribuyente does not exist (%s).', $request->getParameter('id')));
        
              
    }
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $contribuyente = $form->save();

      $this->redirect('contribuyente/index');
    }
  }
  
   protected function getPager($q, $page, $model) {
        $pager = new sfDoctrinePager($model, sfConfig::get('app_nro_x_pagina_contribuyente'));
        $pager->setQuery($q);
        $pager->setPage($page);
        $pager->init();

        return $pager;
    }
    public function executeBuscarContribuyentes(sfWebRequest $request) {
       
        if ($request->isMethod('post')) {
            $nombre = $request->getPostParameter("nombre");
            $apellido = $request->getPostParameter("apellido");
              $dni = $request->getPostParameter("dni");
        } else {
            $nombre = $request->getGetParameter("nombre");
            $apellido = $request->getGetParameter("apellido");
            $dni = $request->getPostParameter("dni");
        }
        $this->contribuyentes = $this->getPager(ContribuyenteTable::getBuscarContribuyentes($nombre, $apellido,$dni), $request->getGetParameter('page'), "Contribuyente");
        if ($request->isXmlHttpRequest()) {
            return $this->renderPartial("contribuyente/listadoContribuyentes", array('contribuyentes' => $this->contribuyentes));
        }
    }
    public function executeBuscarCalle(sfWebRequest $request) {
        $this->setLayout("busqueda");
    }
    public function executeBuscarBarrio(sfWebRequest $request) {
        $this->setLayout("busqueda");
    }
//      public function executeAdminTelefono(sfWebRequest $request) {
//        
//        $this->contribuyente_id = $request->getParameter("id");
//        $this->contribuyente = Doctrine_Core::getTable('Contribuyente')->find(array($request->getParameter('id'))); 
//        
//         
//        $this->getResponse()->setTitle('Contribuyente ('.$this->contribuyente.")",false );    
//        $this->setLayout("busqueda");
//    }
     public function executeFiltrarBarrio(sfWebRequest $request) {
        if ($request->isMethod('post')) {
            $dato = $request->getPostParameter("dato");
        } else {
            $dato = $request->getGetParameter("dato");
        }
        $this->barrio = $this->getPager(BarrioTable::getBuscarBarrios($dato), $request->getGetParameter('page'), "Barrio");
        if ($request->isXmlHttpRequest()) {
            return $this->renderPartial("contribuyente/resultadoBarrios", array('barrio' => $this->barrio));
        }
    }
     public function executeFiltrarCalle(sfWebRequest $request) {
        if ($request->isMethod('post')) {
            $dato = $request->getPostParameter("dato");
        } else {
            $dato = $request->getGetParameter("dato");
        }
        $this->calle = $this->getPager(CalleTable::getBuscarCalles($dato), $request->getGetParameter('page'), "Calle");
        if ($request->isXmlHttpRequest()) {
            return $this->renderPartial("contribuyente/resultadoCalles", array('calle' => $this->calle));
        }
    }
}
